package com.xuxin.baby.model;

import com.xuxin.baby.bean.BaseBean;
import com.xuxin.baby.contract.ChildRiskContract;
import com.xuxin.baby.network.Retrofit;
import com.xuxin.baby.network.RetrofitApi;
import com.xuxin.baby.network.myObserver;
import com.xuxin.baby.presenter.ChildRiskPresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.observers.DisposableObserver;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * Created by xu_xin
 * Created on 2020/10/22 0022
 * 0-12个月的危险信号
 */
public class ChildRiskModel implements ChildRiskContract.Model {
    @Override
    public void getChildRisk(ChildRiskPresenter presenter) {
        Retrofit.getInstance().createReq(RetrofitApi.class)
                .getData()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new myObserver<BaseBean>() {
                    @Override
                    public void onNextX(@NonNull BaseBean baseBean) {
                        if (baseBean.isSuccess()) {
                            presenter.onSuccess(baseBean);
                        } else {
                            presenter.onError(baseBean);
                        }
                    }

                    @Override
                    public void onError(BaseBean baseBean) {
                        presenter.onError(baseBean);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        presenter.onError(null);
                    }

                    @Override
                    public void onComplete() {
                        presenter.onComplete();
                    }
                });
    }
}